<template>
  <div class="return-parse">
    <div class="return-parse-left" v-if="showResultObject">
      <p class="return-parse-left-title">{{ $t('formSetting.jsCodeBlock.jsObject') }}</p>
      <div class="return-parse-form">
        <div class="return-parse-code">
          <pre class="no-base-tip" v-html="syntaxHighlight(analysisResults)" v-if="analysisResults"></pre>
        </div>
        <p class="return-parse-msg">
          {{ $t('formSetting.jsCodeBlock.runTip') }}
        </p>
      </div>
    </div>
    <div class="return-parse-right">
      <p class="return-parse-left-title" v-if="showResultObject"> {{ $t('formSetting.jsCodeBlock.createAlias') }} </p>
      <div class="alias">
        <div
          class="alias-item"
          v-for="(item, index) in resultAliasPath"
          :key="index"
        >
          <el-input
            placeholder="JSON Path"
            clearable
            :value="item.aliasPath"
            disabled
          >
          </el-input>
          <el-input
            :placeholder="$t('formSetting.jsCodeBlock.aliasPlaceholder')"
            clearable
            v-model="item.aliasName"
            maxlength="50"
            @input="onInput"
          >
          </el-input>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* vue */
import { defineComponent, toRefs, ref, unref, onMounted } from 'vue';
/* util */
import { isObjectString, syntaxHighlight } from '../model/index';
import { uuid } from 'pub-bbx-utils';
import { i18n } from '@src/locales';
export default defineComponent({
  name: 'return-parse',
  props: {
    resultAliasPath: {
      type: Array,
      default: () => [],
    },
    analysisResults: {
      type: String,
      default: () => '',
    },
    field: {
      type: Object,
      default: () => ({})
    },
    showResultObject: {
      type: Boolean,
      default: ()=> false
    }
  },
  setup(props, { emit }) {
    const { fields, field, code, resultAliasPath, analysisResults } = toRefs(props);
    const pending = ref(false);
    onMounted(() => {
    });
    /** 别名名称修改*/
    const onInput = () => {
      emit('outResultAliasPath', resultAliasPath.value);
    };
    return {
      pending,
      syntaxHighlight,
      onInput,
    };
  },
});
</script>
<style lang="scss" scoped>
.return-parse {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  &-left {
    margin-right: 16px;
    width: 320px;
    &-title {
      font-size: 14px;
      color: #262626;
      margin-bottom: 8px;
    }
    .return-parse-form {
      .return-parse-code {
        width: 100%;
        height: 300px;
        border: 1px solid #e4e7ed;
        border-radius: 4px;
      }
    }
    .return-parse-msg {
      font-size: 12px;
      margin-top: 8px;
      color: $text-color-secondary;
    }
  }
  &-right {
    flex: 1;
    .alias {
      &-item {
        display: flex;
        row-gap: 40px;
        column-gap: 8px;
        margin-bottom: 8px;
        .icon-delete {
          line-height: 32px;
          cursor: pointer;
          &:hover {
            color: #e84040;
          }
        }
      }
    }
  }
  ::v-deep pre {
    color: #bfbfbf;
    padding: 12px 16px;
    width: 100%;
    height: 100%;
    overflow: auto;
    margin-bottom: 0;
    .string {
      color: green;
    }
    .number {
      color: #ed6a0c;
    }
    .boolean {
      color: blue;
    }

    .null {
      color: magenta;
    }
    .key {
      color: #08979c;
    }
  }
}
</style>
